﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess;
using ExaminationSys.DataAccess.Entity;
using ExaminationSys.DataAccess.Repository;

namespace ExaminationSys
{
    public partial class ChangePassword : BasePage
    {
        public string LoginName { get; set; }
        public int DiligentRank = 0;
        public int ChampionRank = 0;
        public string LoginCount { get; set; }
        public string LastLoginTime { get; set; }

        private static readonly LoginLogService Proxy = ObjectFactory<LoginLogService>.Create();
        private static readonly TeacherInfoService ProxyTeacherInfo = ObjectFactory<TeacherInfoService>.Create();
        private static readonly SubSectionInfoService ProxySubSection = ObjectFactory<SubSectionInfoService>.Create();
        private static readonly SubSectionDetailInfoService ProxySubSectionDetailInfo = ObjectFactory<SubSectionDetailInfoService>.Create();

        private static readonly StudentRankService ProxyStudentRankService = ObjectFactory<StudentRankService>.Create();
        private static readonly StudentService ProxyStudentService = ObjectFactory<StudentService>.Create();
        public List<SubSectionInfo> SubSectionInfoCollection = new List<SubSectionInfo>();


        public List<SubSectionDetailInfo> GetListBySubSectionId(Guid subSectionid)
        {
            return ProxySubSectionDetailInfo.GetListBySubSectionId(subSectionid);
        }

        public SubSectionDetailInfo CurrentSelectItem = new SubSectionDetailInfo();

        //级别名称
        public string LevelName { get; set; }
        public int KnowlegdeLevel = 0;
        private Guid subDetailId = Guid.Empty;
        public Guid ID { get; set; }
        public string TeacherName { get; set; }
        public StringBuilder htmlStr = new StringBuilder();
        protected void Page_Load(object sender, EventArgs e)
        {

           // KnowlegdeLevel = base.GetCurrentStudentLevel();

            if (!IsPostBack)
            {
                base.ResetSession();
                var loginInfo = Session["StudentInfo"] as Student;
                if (loginInfo != null)
                {
                    var rank = ProxyStudentRankService.GetDiligentRankBStudentId(loginInfo.ID.ToString());
                    DiligentRank = rank != null ? rank.Rank : ProxyStudentService.GetStudentCount();
                    rank = ProxyStudentRankService.GetChampionRankBStudentId(loginInfo.ID.ToString());
                    ChampionRank = rank != null ? rank.Rank : ProxyStudentService.GetStudentCount();
                    LoginName = loginInfo.UserName;
                   // if (KnowlegdeLevel == 0) KnowlegdeLevel = (int)EnumLevel.初级;
                   // LevelName = Enum.GetName(typeof(EnumLevel), KnowlegdeLevel);
                    //SubSectionInfoCollection = ProxySubSection.GetListByKnowlegdeLevel(KnowlegdeLevel);
                    var log = Proxy.GetLoginLogByUserId(loginInfo.LoginID, (int)LoginType.登录);
                    LastLoginTime = log != null
                                        ? log.LoginTime.ToString("yyyy.MM.dd HH:mm")
                                        : DateTime.Now.ToString("yyyy.MM.dd HH:mm");
                    var loginCountTmp = Proxy.GetLoginCount(loginInfo.LoginID, (int)LoginType.登录);
                    LoginCount = loginCountTmp == 0 ? "1" : loginCountTmp.ToString();
                    
                }
                else
                {
                    Response.Redirect("Index.aspx");
                }

            }
        }
    }
}